﻿using System.Windows;
using static WPF_Minesweeper.GameEnum;

namespace WPF_Minesweeper
{
    /// <summary>
    /// OptionsWindows.xaml 的交互逻辑
    /// </summary>
    public partial class OptionsWindows : Window
    {
        public OptionsWindows()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载事件
        /// </summary>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 获取主窗体
            MainWindow main;
            main = (MainWindow)Owner;
            // 设置菜单难度状态
            SetMenuLevelState(main._level);
        }

        /// <summary>
        /// 设置难度菜单状态
        /// </summary>
        /// <param name="level"> 难度级别 </param>
        private void SetMenuLevelState(Level level)
        {
            switch (level)
            {
                case Level.Primary:
                    PrimaryBtn.IsChecked = true;
                    IntermediateBtn.IsChecked = false;
                    AdvancedBtn.IsChecked = false;
                    break;
                case Level.Intermediate:
                    PrimaryBtn.IsChecked = false;
                    IntermediateBtn.IsChecked = true;
                    AdvancedBtn.IsChecked = false;
                    break;
                case Level.Advanced:
                    PrimaryBtn.IsChecked = false;
                    IntermediateBtn.IsChecked = false;
                    AdvancedBtn.IsChecked = true;
                    break;
            }
        }

        /// <summary>
        /// 确定按钮点击事件
        /// </summary>
        private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
        {
            // 获取主窗体
            MainWindow main;
            main = (MainWindow)Owner;
            // 获取选择的难度
            if (PrimaryBtn.IsChecked == true)
                main._level = Level.Primary;
            else if (IntermediateBtn.IsChecked == true)
                main._level = Level.Intermediate;
            else if (AdvancedBtn.IsChecked == true)
                main._level = Level.Advanced;
            // 重新加载游戏
            main.ResetGame();
            // 关闭当前窗体
            Close();
        }

        /// <summary>
        /// 取消按钮点击事件
        /// </summary>
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

    }
}
